﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace Anywhere.Common
{
    public class DelegateCommand<T> : ICommand
    {
        public DelegateCommand(Action<T> execMethod, Func<T, bool> canExecMethod)
        {
            _canExec = canExecMethod;
            _exec = execMethod;
        }

        private readonly Func<T, bool> _canExec;
        private readonly Action<T> _exec;


        public bool CanExecute(object parameter)
        {
            return _canExec((T)parameter);
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            _exec((T)parameter);
        }
    }

    public class DeledateCommand : ICommand
    {
        private readonly Func<bool> _canExec;
        private readonly Action _exec;

        public DeledateCommand(Func<bool> canExec, Action exec)
        {
            _canExec = canExec;
            _exec = exec;
        }

        public bool CanExecute(object parameter)
        {
            return _canExec();
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            _exec();
        }
    }
}
